package com.ben.chatroom.config;

import com.ben.chatroom.common.util.SpringContextUtil;
import com.ben.chatroom.common.zk.CuratorZKclient;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author
 */
@Configuration
public class ZkClientConfig implements ApplicationContextAware {

  @Value("${zookeeper.connect.url}")
  private String zkConnect;

  @Value("${zookeeper.connect.sessionTimeout}")
  private String zkSessionTimeout;


  @Bean(name = "curatorZKclient")
  public CuratorZKclient curatorZKclient() {
    return new CuratorZKclient(zkConnect, zkSessionTimeout);
  }

  @Override
  public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    SpringContextUtil.setContext(applicationContext);
  }
}
